class Person implements Cloneable {
    public String name;

    public Person(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}


class Example{
    String str = new String("good");
    char[ ] ch = { 'a' , 'b' , 'c' };

    public void change(String str,char ch[ ]){
        str = "test ok";
        ch[0] = 'g';
    }

    public static void main12(String[] args){
        Example ex = new Example();
        ex.change(ex.str,ex.ch);
        System.out.print(ex.str + " and ");
        System.out.print(ex.ch);
    }
}

class TestClass {

    private static void testMethod(){

        System.out.println("testMethod");

    }

    public static void main(String[] args) {

        ((TestClass)null).testMethod();
    }

}



//如果要写一个自定义异常，一定要继承一个异常
// extends Exception 编译时异常
// extends RuntimeException 运行时异常

class NameException extends RuntimeException {
    public NameException(String message) {
        super(message);
    }
}

class PasswordException extends RuntimeException {
    public PasswordException(String message) {
        super(message);
    }
}


class LogIn {
    private String userName = "admin";

    private String password = "123456";

    public void loginInfo(String userName, String password) {
        if (!this.userName.equals(userName)) {
            //用户名有问题
            throw new NameException("用户名错误！");
        }
        if (!this.password.equals(password)) {
            //密码有问题
            throw new PasswordException("密码错误！");
        }
        System.out.println("登陆成功");
    }
}


public class Test {

    public static void main5(String[] args) {
        LogIn logIn = new LogIn();
        /*try {
            logIn.loginInfo("admin", "1234567");
        } catch (NameException e) {
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
    }*/
        logIn.loginInfo("admin", "1234567");

    }


    public static void main4(String[] args) {
        System.out.println("before......");
        try {
            System.out.println(10 / 0);
            System.out.println("abcd");

        } catch (ArithmeticException e) {
            e.printStackTrace();
            System.out.println("我来处理 ArithmeticException 异常了！");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("我来处理 NullPointerException 异常了！");
        }
        System.out.println("after......");
    }


    public static void func() throws CloneNotSupportedException {
        int a = 10;
        if (a == 10) {
            throw new CloneNotSupportedException("hahaha!");
        }
    }

    public static void main3(String[] args) {
        try {
            func();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }


    public static void main2(String[] args) throws CloneNotSupportedException {
        Person person = new Person("张三");
        Person person2 = (Person) person.clone();

    }



    /*public static void func() {
        func();
    }

    public static void main1(String[] args) {
        func();*/


    //System.out.println(10/0);
    //System.out.println("abc");

        /*int[] array = null;
        System.out.println(array[0]);*/

        /*int[] array2 = {1,2,3,4,5};
        System.out.println(array2[10]);
    }*/
}
